package com.h3c.nem.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.eos.common.util.IdWorker;
import com.h3c.nem.entity.SdRequestRecord;
import com.h3c.nem.mapper.SdRequestRecordMapper;
import com.h3c.nem.service.SdRequestRecordService;
import com.h3c.nem.service.ThreadPoolService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;

/**
* @author f23104
* @description 针对表【sd_request_record(入职登记调用SAP接口参数记录)】的数据库操作Service实现
* @createDate 2022-08-11 18:40:28
*/
@Service
public class SdRequestRecordServiceImpl extends ServiceImpl<SdRequestRecordMapper, SdRequestRecord>
    implements SdRequestRecordService{

    @Resource
    ThreadPoolService threadPoolService;

    /**
     * 记录SAP接口参数
     * @param workerId 预备员工
     * @param type  调用场景 （生成预备工号 更新预备员工 生成正式工号。。。）
     * @param reqName  接口名
     * @param object    参数
     */
    public void addReqRecord(String workerId, String type, String reqName, String param, String response) {
        Thread thread = new Thread(() -> saveRecord(workerId, type, reqName, param, response));
        threadPoolService.submitTask(thread);
    }

    public void saveRecord(String workerId, String type, String reqName, String param, String response) {
        SdRequestRecord record = new SdRequestRecord();
        record.setRecordId(IdWorker.nextId() + "");
        record.setWorkerId(workerId);
        record.setType(type);
        record.setRequestName(reqName);
        record.setParam(param);
        record.setResponse(response);
        record.setCreateTime(new Date());
        save(record);
    }
}




